/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 */

/**
 * 解析命令行中-p module=配置的module和target信息
 *
 * @param configModuleStr -p module=配置的参数
 */
export function parseTargets(configModuleStr: string | undefined): Map<string, string[]> {
  const moduleTargets = new Map<string, string[]>();
  if (configModuleStr === undefined) {
    return moduleTargets;
  }
  const modules = configModuleStr.split(',');
  for (const module of modules) {
    const values = module.split('@');
    let index = 0;
    const targets = ['all'];
    for (const value of values.slice(1)) {
      if (value !== '') {
        targets[index++] = value;
      }
    }
    moduleTargets.set(values[0], targets);
  }
  return moduleTargets;
}
